<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title></title>
  </head>
  <body>
    <div id="app">
      <div :class="{ active: isActive }">布尔值</div>
      <div
        class="static"
        :class="{ active: isActive, 'text-danger': hasError }"
      >
        class 合并
      </div>
      <div :class="classObject">对象</div>
      <div :class="classComputedObject">计算属性</div>
    </div>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
      const { createApp, ref, reactive, computed } = Vue;

      createApp({
        setup() {
          const isActive = ref(true);
          const hasError = ref(false);
          const classObject = reactive({
            active: true,
            "text-danger": false,
          });
          const error = ref(null);
          const classComputedObject = computed(() => ({
            active: isActive.value && !error.value,
            "text-danger": error.value && error.value.type === "fatal",
          }));

          return {
            isActive,
            hasError,
            classObject,
            classComputedObject,
          };
        },
      }).mount("#app");
    </script>
  </body>
</html>
